//
//  BaseViewController.m
//  翻转效果
//
//  Created by Lucifer on 15-5-19.
//  Copyright (c) 2015年 xuxzhou. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()
@property ( nonatomic , strong ) UIBarButtonItem *returnButton;

@end

@implementation BaseViewController

-(instancetype) init{
    self = super.init;
    if (self){
//        self.leftButtonStyle = BarButtonStyleReturn;
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    self.returnButton = ({
        UIButton *button = [[UIButton alloc] initWithFrame: CGRectMake( 0 , 0 , 30 , 30 )];
        [button setImage: [UIImage imageNamed: @"back_normal"] forState: UIControlStateNormal];
        button.contentEdgeInsets = UIEdgeInsetsMake( 0 , - 20 , 0 , 0 );
        [button addTarget: self action: @selector( returnButtonClick: ) forControlEvents: UIControlEventTouchUpInside];
        UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView: button];
        leftBarButton;
    });
    self.navigationItem.leftBarButtonItem = self.returnButton;
}

-(void) returnButtonClick: (UIButton *) button{
    if (self.navigationController){
        [self.navigationController popViewControllerAnimated: YES];
    }
    else{
        [self dismissViewControllerAnimated: YES completion: nil];
    }
}

-(void) viewWillAppear: (BOOL) animated{
    [super viewWillAppear: animated];
    [self.navigationController.navigationBar setTitleTextAttributes: @{
                                                                       NSForegroundColorAttributeName : [UIColor whiteColor] ,
                                                                       NSFontAttributeName : [UIFont systemFontOfSize: 18.0f]
                                                                       }];
    [self.navigationController.navigationBar setBackgroundColor: [UIColor colorWithRed: 27 / 255.0 green: 129 / 255.0 blue: 172 / 255.0 alpha: 1]];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
